﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data;
namespace DnDDB
{


    public class Equipment
    {

        // non-derived variables
        // non derived variables will have accessors and mutators
        // and add method as well

        protected string equip_name;
        protected int weight;
        protected int cost;
		protected int quantity;
		protected bool equipped;

        public Equipment(string name)
        {
			equip_name = name;
            getMySQL get = new getMySQL();
           	string dbCommand = "SELECT * FROM `Equipment` WHERE " +
			"Equipment.name = '" + name + "';";
        	DataRow dt = get.GetMySQLFilledRow(dbCommand);
			this.weight = Convert.ToInt32(dt["weight"]);
			this.cost = Convert.ToInt32(dt["value"]);
			quantity = 1;
			equipped = false;
        }

        public Equipment(string name, bool equipped)
        {
            equip_name = name;
            getMySQL get = new getMySQL();
            string dbCommand = "SELECT * FROM `Equipment` WHERE " +
            "Equipment.name = '" + name + "';";
            DataRow dt = get.GetMySQLFilledRow(dbCommand);
            this.weight = Convert.ToInt32(dt["weight"]);
            this.cost = Convert.ToInt32(dt["value"]);
            quantity = 1;
            this.equipped = equipped;
        }

        public Equipment(string equip_name, int weight, int cost, int quant, bool equip)
        {
            // set all the derived attributes
            this.equip_name = equip_name;
            this.weight = weight;
            this.cost = cost;
			quantity = quant;
			equipped = equip;

        }


		public bool armorp(){
			getMySQL get = new getMySQL();
            string dbcommand = "SELECT * FROM `Equipment` eqp, `Equipment_is_Armor` eia WHERE eqp.id = eia.Equipment_id AND eqp.name = '" + equip_name + "';";
			DataTable dt = get.GetMySQLFilledTable(dbcommand);
			if(dt.Rows.Count == 0){
				return false;
			} else{
				return true;
			}
		}
		
		public bool weaponp(){
			getMySQL get = new getMySQL();
            string dbcommand = "SELECT * FROM `Equipment` eqp, `Equipment_is_Weapon` eiw WHERE eqp.id = eiw.Equipment_id AND eqp.name = '" + equip_name + "';";
			DataTable dt = get.GetMySQLFilledTable(dbcommand);
			if(dt.Rows.Count == 0){
				return false;
			} else{
				return true;
			}
		}



        public string getEquipmentName()
        {
            return equip_name;
        }
        public int getWeight()
        {
            return weight;
        }
        public int getCost()
        {
            return cost;
        }
        public int getQuantity()
        {
            return quantity;
        }
        public bool getEquipped()
        {
            return equipped;
        }
        public void setEquipmentName(string name)
        {
            equip_name = name;
        }
        public void setWeight(int newWeight)
        {
            weight = newWeight;
        }
        public void setCost(int newCost)
        {
            cost = newCost;
        }
        public void setQuantity(int newQuantity)
        {
            quantity = newQuantity;
        }
        public void setEquipped(bool newEquipped)
        {
            equipped = newEquipped;
        }
    }
}
